
(function($){
	$.formatTime =  function(time,format){
		var o = {
			"M+" : time.getMonth() + 1,
			"d+" : time.getDate(),
			"h+" : time.getHours(),
			"m+" : time.getMinutes(),
			"s+" : time.getSeconds(),
			"q+" : Math.floor((time.getMonth() + 3) / 3),
			"S" : time.getMilliseconds()
		}
		if (/(y+)/.test(format))
		{
			format = format.replace(RegExp.$1, (time.getFullYear() + "").substr(4- RegExp.$1.length));
		}
		for (var k in o)
		{
			if (new RegExp("(" + k + ")").test(format))
			{
				format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]: ("00" + o[k]).substr(("" + o[k]).length));
			}
		}
		return format;
	};

	$.subStr = function(str,l,point){//省略字符串
		if(str.length <= l)
			return str;
		else if(!point){
			return str.substring(0,l);
		}
		else
			return str.substring(0,l)+'...';
	};

	$.getGender = function(gender){
		switch(gender){
			case 'f':return '女';
			case 'm':return '男';
			case 'n':return '未知';
			case '女':return 'f';
			case '男':return 'm';
			case '未知':return 'n';
			default : return '';
		}
	};

	$(window).bind("scroll", function(){
		var at = $(document).scrollTop();//元素离页面顶部的高度
		if(at<$(".page").offset().top+$(window).height()) {
			if(!$(".nav .rightSearch").hasClass("now")){
				$(".nav .rightSearch").addClass("now");
				if($(".nav .rightChoose").hasClass('now')) $(".nav .rightChoose").removeClass('now');
				else $(".nav .rightShare").removeClass('now');
			}
		}
		else if($(".push-panel").css("display")!="none" && at>$(".push-panel").offset().top-$(window).height()){
			if(!$(".nav .rightShare").hasClass("now")){
				$(".nav .rightShare").addClass("now");
				if($(".nav .rightChoose").hasClass('now')) $(".nav .rightChoose").removeClass('now');
				else $(".nav .rightSearch").removeClass('now');
			}
		}
		else{
			if(!$(".nav .rightChoose").hasClass("now")){
				$(".nav .rightChoose").addClass("now");
				if($(".nav .rightSearch").hasClass('now')) $(".nav .rightSearch").removeClass('now');
				else $(".nav .rightShare").removeClass('now');
			}
		}
	});

	//固定滚动条
	$.bindScroll = function(bind){
		if(bind){
			$("BODY").css({"overflow":"hidden"});
			return true;
		}
		else{
			$("BODY").css({"overflow":"auto"});
			return false;
		}
	}

	$.searchInArray = function(index,weibos,searchContent){
		if(searchContent=="index")
			for(var i=0; i<weibos.length; i++){
				if(index==weibos[i].index) return i;
			}
		else if(searchContent=="mid"){
			for(var i=0; i<weibos.length; i++){
				if(index==weibos[i].mid) return i;
			}
		}
		return -1
	}

	$.waitState=function(show,word,button){
		var _this = button;
		if(show){
			_this.addClass("disabled");
			if(_this[0].nodeName == "INPUT") _this.attr("value", word);
			else _this.html(word);
		}
		else{
			_this.removeClass("disabled");
			if(_this[0].nodeName == "INPUT") _this.attr("value", word);
			else _this.html(word);
		}
	}

	$.setWaitState=function(status){
		if(status){
	    $.waitState(true, "正在加载", $(".more"));
	    $.waitState(true, "搜索中..", $(".search-btn"));
	    $.waitState(true, "筛 选", $(".screen-r input"));
		}
	  else
	  {
	    $.waitState(false, "显示更多", $(".more"));
	    $.waitState(false, "搜 索", $(".search-btn"));
	    $.waitState(false, "筛 选", $(".screen-r input"));
	  }

	}

	$.matchStr=function(str, substr){
		var re = new RegExp(substr,"gi");
		var sublength=substr.length;
		var strs=[];
		var i=0;
		while(str.search(re)!=-1){
			var n = str.search(re);
			strs[i++]=str.substring(0,n)+'<span style="color:red">'+substr+'</span>';
			str=str.substring(n+sublength);
		}
		strs[i++]=str;
		var newstr='';
		for(var j=0; j<i; j++){
			newstr += strs[j];
		}
		return newstr;
	}

	$.matchStrs = function(str, substr){
		var re = $.trim(substr);
		var key;
		var i=0;
		var newstr=str;
		while(re.search(' ')!=-1){
			var n = re.search(' ');
			key = re.substring(0,n);
			newstr = $.matchStr(newstr,key);
			re = $.trim(re.substring(n));
		};
		newstr = $.matchStr(newstr,re);
		return newstr;
	}



})(jQuery);